const express = require('express')
// const path = require('path')
const app = express()
const routers = require('./routers/list')

// const webpack = require('webpack')
// const middle = require('webpack-dev-middleware')
// const webpackConfig = require('../webpack.config.js')
// const compiler = webpack(webpackConfig)

// app.use(middle(compiler))
app.use(express.json())
app.use(express.urlencoded({ extended: true }))

app.use((req, res, next) => {
  res.header('Access-Control-Allow-Origin', '*')
  res.header(
    'Access-Control-Allow-Headers',
    'Content-Type,Content-Length, Authorization, Accept, X-Requested-With , yourHeaderFeild'
  )
  res.header('Access-Control-Allow-Methods', 'PUT, POST, GET, DELETE,OPTIONS')
  next()
})

app.use('/api', routers)

app.get('*', (req, res) => {
  res.send([])
})

app.listen(3000, () => {
  console.log('监听成功: http://localhost:3000')
})
